layui.use(['layer', 'form', 'admin', 'laydate', 'ax', 'formSelects','upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload;
    
    form.on('select(status)', function(data){
    	if(data.value == '图片'){
    		$("#imgid").show();
    		$("#ypid").hide();
    		$("#spid").hide();
    	}else if(data.value == '音频'){
    		$("#imgid").hide();
    		$("#ypid").show();
    		$("#spid").hide();
    	}else if(data.value == '视频'){
    		$("#imgid").hide();
    		$("#ypid").hide();
    		$("#spid").show();
    	}
    });
    
    upload.render({
        elem: '#test1'
        ,url: 'https://www.idjglobalapp.com/app-servce/v1/api/upload' //改成您自己的上传接口
        ,method: 'POST'
        ,done: function(res){
            //上传完毕
            if(res.code == 1){
            	layer.msg('上传成功') 
            	layui.$('#uploadDemoView1').removeClass('layui-hide').find('img').attr('src', res.data);
            	$("#urls").val('');
            	$("#urls").val(res.data);
                //$('#uploadDemoView').append('<hr><video width="420px" height="280px" controls="controls" autobuffer="autobuffer"  loop="loop" src="'+ res.data +'" style="width:200px;height:120px;"></video>');
            }
         }
      });
    
    upload.render({
    	elem: '#test2'
    		,url: 'https://www.idjglobalapp.com/app-servce/v1/api/upload' //改成您自己的上传接口
    			 ,accept: 'audio' //音频
    			,method: 'POST'
    				,done: function(res){
    					//上传完毕
    					if(res.code == 1){
    						layer.msg('上传成功') 
    						layui.$('#uploadDemoView2').removeClass('layui-hide').find('video').attr('src', res.data);
    						$("#urls").val('');
    		            	$("#urls").val(res.data);
    						//$('#uploadDemoView').append('<hr><video width="420px" height="280px" controls="controls" autobuffer="autobuffer"  loop="loop" src="'+ res.data +'" style="width:200px;height:120px;"></video>');
    					}
    				}
    });
    
    upload.render({
    	elem: '#test3'
    		,url: 'https://www.idjglobalapp.com/app-servce/v1/api/upload' //改成您自己的上传接口
    			,accept: 'video' //视频
    			,method: 'POST'
    				,done: function(res){
    					//上传完毕
    					if(res.code == 1){
    						layer.msg('上传成功') 
    						$("#urls").val('');
    						$("#urls").val(res.data);
    						layui.$('#uploadDemoView3').removeClass('layui-hide').find('video').attr('src', res.data);
    						//$('#uploadDemoView').append('<hr><video width="420px" height="280px" controls="controls" autobuffer="autobuffer"  loop="loop" src="'+ res.data +'" style="width:200px;height:120px;"></video>');
    					}
    				}
    });
    
    

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var date = data.field.status;
        var parent$ = window.parent.layui.jquery;
        parent$("#type").val(date);
        parent$("#url").val($("#urls").val());
        parent$("#contex").text($("#content").val());
        parent$("#statuss").siblings("div.layui-form-select").find('dl dd[lay-value=' + 2 + ']').click();
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);
    });
    
});